<?php
class AppController extends Controller {
	var $components = array('Session');
	var $uses = array('User');
	
	function beforeFilter()
	{
		if($this->Session->read('User.role')=='' && $this->params['action']!='login')
		{
			$this->Session->setFlash('Access Denied');	
			$this->redirect('/users/login');
		}

		if(isset($this->params['admin']) && $this->params['admin']=='1' && $this->Session->read('User.role')!='admin')
		{					
				$this->redirect('/users/index');			
		}
		
		/* To check the user status after the login */
		if($this->Session->read('User.id') != '')
		{	
			$this->User->recursive = -1;
			$status = $this->User->find('first',array('conditions'=>array('User.id'=>$this->Session->read('User.id'))));
			if($status['User']['status']=='flagged' && $this->params['action']!='index' && $this->params['controller']!='projects')
			{
				$this->Session->write('User.status','flagged');
				$this->Session->setFlash(__('You just got flagged because you didn\'t submit the Revision within allocated time.', true));			
				$this->redirect('/projects/index');
			}
			if(isset($status['User']) && $status['User']['status'] == 'banned')
			{
				$this->Session->destroy();
				$this->Session->setFlash(__('You just got banned because you didn\'t submit the Assignment within allocated time.', true));	
				$this->redirect('/users/login');				
			}
		}	
		if(isset($status['User']))
			$this->set('total_amount',$status['User']['total_amount']);
		else
			$this->set('total_amount',0);
				
	}
}
?>
